<?php

namespace app\common\exception;

use Exception;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;

class HttpHandle extends Handle
{
    public function render(Exception $e)
    {
        //参数验证错误
        if ($e instanceof ValidateException)
        {
            return json($e->getError(),422);
        }

        //请求异常
        if ($e instanceof HttpException && request()->isAjax())
        {
            return response($e->getMessage(),$e->getStatusCode());
        }


        return parent::render($e); // TODO: Change the autogenerated stub
    }
}

